package com.huanbao.nongwu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huanbao.common.pojo.nwrabc.SysMenu;
import com.huanbao.common.pojo.nwrabc.SysRoleMenu;
import com.huanbao.nongwu.dao.SysMenuDao;
import com.huanbao.nongwu.dao.SysRoleMenuDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysMenusServiceImpl {

    @Autowired
    private SysMenuDao sysMenuDao;

    @Autowired
    private SysRoleMenuDao sysRoleMenuDao;


//	public List<SysMenu> getMenusByUserId(int userId) {
//		List<SysMenu> sysMenus = sysMenuDao.getMenusByUserId(userId);
//		return sysMenus;
//	}

    public List<SysMenu> getAllMenus() {
        QueryWrapper<SysMenu> emp = new QueryWrapper<>();
        emp.eq("ishide", 0).orderByDesc("sortweight");
        List<SysMenu> sysMenus = sysMenuDao.selectList(emp);
        return sysMenus;
    }


    public List<SysMenu> getMenusByRoleId(int roleid) {
        QueryWrapper<SysRoleMenu> emp = new QueryWrapper<>();
        emp.eq("roleid", roleid);
        List<SysRoleMenu> list = sysRoleMenuDao.selectList(emp);
        List<SysMenu> menuList = new ArrayList<>();
        list.stream().forEach(n -> {
            SysMenu sysMenu = new SysMenu();
            sysMenu.setId(n.getMenuid());
            menuList.add(sysMenu);
        });
        return menuList;
    }


}
